package net.daum.demo.Homework10;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class SampleAdapter extends BaseAdapter {
	private List<Make> contentList;
	private final int ID_TITLE_TEXTVIEW = 2;
	
	public SampleAdapter(Activity activity, List<Make> contentList) {
		super();
		this.contentList = contentList;
	}

	@Override
	public int getCount() {
		return this.contentList.size();
	}

	@Override
	public Object getItem(int position) {
		return this.contentList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = this.createItemView(parent.getContext());
		}
		
		TextView titleTextView = (TextView) convertView.findViewById(ID_TITLE_TEXTVIEW);
		
		Make make = this.contentList.get(position);
		
		titleTextView.setText(make.getName());
		
		return convertView;
	}

	private View createItemView(Context context) {
		RelativeLayout relativeLayout = new RelativeLayout(context);
		
		
		RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(100, 100);
		
		TextView titleTextView = new TextView(context);
		layoutParams = new RelativeLayout.LayoutParams(300, 50);
		titleTextView.setLayoutParams(layoutParams);
		titleTextView.setId(ID_TITLE_TEXTVIEW);
		
		relativeLayout.addView(titleTextView);
		return relativeLayout;
	}
}
